/* gpsct08.i - -- INCLUDE FILE TO FIND COST SET (SCT_DET) NON-LSC VERSIO      */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: gpsct08.i 2366 2010-11-10 01:47:19Z zzh                           $: */
/* $Revision: 1.6 $                                                  */
/*V8:ConvertMode=Maintenance                                                  */
/* Revision: 1.4  BY: Robin McCarthy DATE: 01/31/02 ECO: *P000* */
/* $Revision: 1.6 $ BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00F* */
/*-Revision end---------------------------------------------------------------*/

/******************************************************************************/
/*!
    This include file is a copy of gpsct01.i before changes for Linked Site
    Costing were applied to gpsct01.i.  It is used in programs where the
    cost record retrieval should be done literally.  In other words, when a
    target site has been entered, it should not be reinterpreted as the linked
    source site for GL cost retrieval.

    Changes to gpsct01.i may also need to be done to this routine.

    This include file looks for a specific cost-set/part record
    and creates it if not found.

    This procedure does not validate that the specified set name exists.
    It is the responsibility of the calling to do so before invoking
    this file.
*/
/*!
    &set  = the specific set name to use
    &part = the part number
    &site = the site for the cost set.
*/
/******************************************************************************/


find sct_det exclusive-lock
 where sct_det.sct_domain = global_domain and  sct_sim = {&set} and sct_part =
 {&part}
and sct_site = {&site} no-error.

if not available sct_det then do:
   create sct_det. sct_det.sct_domain = global_domain.
   assign sct_sim = {&set}
          sct_part = {&part}
          sct_site = {&site}
          sct_cst_date = today
          recno = recid(sct_det).
end.

for each lngd_det no-lock where lngd_dataset = "sc_mstr"
and lngd_key1 = ""
and lngd_key2 = ""
and lngd_key3 = ""
and lngd_field = "sc_category"
and lngd_lang = global_user_lang
and lookup(lngd_key4, "1,2,3,4,5") <> 0:

   for first spt_det
    where spt_det.spt_domain = global_domain and  spt_site = sct_site
   and spt_sim = sct_sim
   and spt_part = sct_part
   and truncate(spt_pct_ll,0) = decimal(lngd_key4)
   no-lock: end.

   if not available spt_det then do:
      create spt_det. spt_det.spt_domain = global_domain.
      assign spt_site = sct_site
             spt_sim = sct_sim
             spt_part = sct_part
             spt_element = substring(lngd_translation,1,8)
             spt_pct_ll = decimal(lngd_key4)
             recno = recid(spt_det).
   end.
end.
